package pres.lnk.learn.designpattern.h_filter;

import pres.lnk.learn.designpattern.h_filter.criteria.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>过滤器模式</p>
 * @Author lnk
 * @Date 2018/2/8
 */
public class Main {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<Person>();

        persons.add(new Person("Robert","Male", "Single"));
        persons.add(new Person("John","Male", "Married"));
        persons.add(new Person("Laura","Female", "Married"));
        persons.add(new Person("Diana","Female", "Single"));
        persons.add(new Person("Mike","Male", "Single"));
        persons.add(new Person("Bobby","Male", "Single"));


        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);

        System.out.println("单身男性：");
        printPersons(singleMale.filter(persons));

        System.out.println("--------------------");
        System.out.println("单身或是女性：");
        printPersons(singleOrFemale.filter(persons));
    }

    private static void printPersons(List<Person> list){
        for (Person person : list) {
            System.out.println(person);
        }
    }
}
